/***********************************************************************************/
/* Code license:  GNU General Public License v3                                    */
/* Main page:     https://code.google.com/p/library-cross-platform/                */
/* Issue tracker: https://code.google.com/p/library-cross-platform/issues/list     */
/***********************************************************************************/

#ifndef _NEURONET_PARSER_STATE_10_JUN_2011_
#define _NEURONET_PARSER_STATE_10_JUN_2011_

#include "parser.h"
#include "parserstatehandler.h"
#include "string.h"

using namespace std;

#define DECLARE_STATE_FUNCTION(fnc) protected: virtual bool fnc(void);
#define DECLARE_START_STATE_FUNCTION() public: virtual pFunctionPntr statehandler(int);


typedef enum
{
  FILE_RESULT_OK = 0,
  FILE_RESULT_EOF,
  FILE_RESULT_NULL_POINTER,
  FILE_RESULT_SIZE_ZERO,
  FILE_RESULT_BAD_SET,
  FILE_RESULT_FAIL_SET,
  FILE_RESULT_UNKNOWN
} READ_FILE_RESULT;

class parserstate : public parser, public parserstatehandler
{
public:
  parserstate();
  parserstate(std::istream*);
  virtual ~parserstate();

  virtual void start();

protected:
    virtual READ_FILE_RESULT readRawData(string&);
    virtual READ_FILE_RESULT readRawData();
    virtual bool readRawDataString();
    virtual bool isComment();
    virtual bool eos(char &c); //check is end-of string

    const string &getRawData();
    void setRawData(string &);
    void clearRawData();

private:
    string rawdata;
/*================================================*/
/*          STATE FUNCTION DECLARATION            */
/*================================================*/
  DECLARE_START_STATE_FUNCTION()

  DECLARE_STATE_FUNCTION(stateStart)
  DECLARE_STATE_FUNCTION(stateExit)

protected:
};

/******************************************************************************/
/************************ MACROS FOR STATE MAP ********************************/
/******************************************************************************/

#define START_STATE_MAP_BASE_CLASS(THIS_CLASS)\
 pFunctionPntr THIS_CLASS::statehandler(int state)\
 {\
   pFunctionPntr funcstate = null;\
   switch(state)\
   {\
     default:\
      funcstate = NULL;\
      break;\


#define START_STATE_MAP(BASE_CLASS, THIS_CLASS)\
 pFunctionPntr THIS_CLASS::statehandler(int state)\
 {\
   pFunctionPntr funcstate = null;\
   switch(state)\
   {\
     default:\
      funcstate = BASE_CLASS::statehandler(state);\
      break;\

#define END_STATE_MAP()\
   }\
   return funcstate;\
 }\


#define STATE(state, func)\
  case state:\
   funcstate = (pFunctionPntr)&func;\
   break;\



/******************************************************************************/
/************************ STATE DEFINITION ************************************/
/******************************************************************************/
enum _tag_parserstate_state_enum
{
  START_STATE = 0,
  STATE_EXIT,
  PARSERSTATE_BASE_MAX
};

#endif //_NEURONET_PARSER_STATE_10_JUN_2011_
